home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / rwvector.lha / RWVector2.1 / src / mathpack / dswap.f < prev    next >
Text File  |  1989-08-17  |  4KB  |  110 lines

  1. c   imsl routine name   - vbla=dswap                                    vbdl0010
  2. c
  3. c-----------------------------------------------------------------------
  4. c
  5. c   computer            - vax/double
  6. c
  7. c   latest revision     - january 1, 1978
  8. c
  9. c   purpose             - interchange vectors x and y, both
  10. c                           double precision
  11. c
  12. c   usage               - call dswap (n,dx,incx,dy,incy)
  13. c
  14. c   arguments    n      - length of vectors x and y. (input)
  15. c                dx     - double precision vector of length
  16. c                           max(n*iabs(incx),1). (input/output)
  17. c                           dswap interchanges x(i) with y(i) for
  18. c                           i=1,...,n.
  19. c                           x(i) and y(i) refer to specific elements
  20. c                           of dx and dy, respectively. see incx and
  21. c                           incy argument descriptions.
  22. c                incx   - displacement between elements of dx. (input)
  23. c                           x(i) is defined to be..
  24. c                           dx(1+(i-1)*incx) if incx.ge.0 or
  25. c                           dx(1+(i-n)*incx) if incx.lt.0.
  26. c                dy     - double precision vector of length
  27. c                           max(n*iabs(incy),1). (input/output)
  28. c                incy   - displacement between elements of dy. (input)
  29. c                           y(i) is defined to be..
  30. c                           dy(1+(i-1)*incy) if incy.ge.0 or
  31. c                           dy(1+(i-n)*incy) if incy.lt.0.
  32. c
  33. c   precision/hardware  - double/all
  34. c
  35. c   reqd. imsl routines - none required
  36. c
  37. c   notation            - information on special notation and
  38. c                           conventions is available in the manual
  39. c                           introduction or through imsl routine uhelp
  40. c
  41. c   copyright           - 1978 by imsl, inc. all rights reserved.
  42. c
  43. c   warranty            - imsl warrants only that imsl testing has been
  44. c                           applied to this code. no other warranty,
  45. c                           expressed or implied, is applicable.
  46. c
  47. c-----------------------------------------------------------------------
  48. c
  49.       subroutine dswap  (n,dx,incx,dy,incy)
  50. c
  51. c                                  specifications for arguments
  52.       double precision   dx(1),dy(1)
  53.       integer            n,incx,incy
  54. c                                  specifications for local variables
  55.       double precision   dtemp1,dtemp2,dtemp3
  56.       integer            i,ix,iy,m,mp1,ns
  57. c                                  first executable statement
  58.       if (n.le.0) return
  59.       if (incx.eq.incy) if (incx-1) 5,15,35
  60.     5 continue
  61. c                                  code for unequal or nonpositive
  62. c                                    increments.
  63.       ix = 1
  64.       iy = 1
  65.       if (incx.lt.0) ix = (-n+1)*incx+1
  66.       if (incy.lt.0) iy = (-n+1)*incy+1
  67.       do 10 i=1,n
  68.          dtemp1 = dx(ix)
  69.          dx(ix) = dy(iy)
  70.          dy(iy) = dtemp1
  71.          ix = ix+incx
  72.          iy = iy+incy
  73.    10 continue
  74.       return
  75. c                                  code for both increments equal to 1
  76. c                                    clean-up loop so remaining vector
  77. c                                    length is a multiple of 3.
  78.    15 m = n-(n/3)*3
  79.       if (m.eq.0) go to 25
  80.       do 20 i=1,m
  81.          dtemp1 = dx(i)
  82.          dx(i) = dy(i)
  83.          dy(i) = dtemp1
  84.    20 continue
  85.       if (n.lt.3) return
  86.    25 mp1 = m+1
  87.       do 30 i=mp1,n,3
  88.          dtemp1 = dx(i)
  89.          dtemp2 = dx(i+1)
  90.          dtemp3 = dx(i+2)
  91.          dx(i) = dy(i)
  92.          dx(i+1) = dy(i+1)
  93.          dx(i+2) = dy(i+2)
  94.          dy(i) = dtemp1
  95.          dy(i+1) = dtemp2
  96.          dy(i+2) = dtemp3
  97.    30 continue
  98.       return
  99.    35 continue
  100. c                                  code for equal, positive, nonunit
  101. c                                    increments.
  102.       ns = n*incx
  103.       do 40 i=1,ns,incx
  104.          dtemp1 = dx(i)
  105.          dx(i) = dy(i)
  106.          dy(i) = dtemp1
  107.    40 continue
  108.       return
  109.       end
  110.